/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.latesis.dao.hibernate;

import com.latesis.bean.AlertaBean;
import com.latesis.bean.GrupoBean;
import com.latesis.bean.GrupoBean;
import com.latesis.dao.GrupoDAO;
import java.util.List;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author acabrera
 */
@Transactional(propagation=Propagation.SUPPORTS)
public class GrupoDAOHibernateImpl extends HibernateDaoSupport implements GrupoDAO{
    public GrupoBean guardar(GrupoBean bean) {
         getHibernateTemplate().saveOrUpdate(bean);
         return bean;
    }

    public void borrar(GrupoBean bean) {
        getHibernateTemplate().delete(bean);
    }

    public GrupoBean buscar(GrupoBean bean) {
        return getHibernateTemplate().get(GrupoBean.class, bean.getId());
    }

    public List<GrupoBean> buscarTodos() {
        return (List<GrupoBean>)getHibernateTemplate().find("from GrupoBean ");
    }

    public List<GrupoBean> buscarCustom(int start, int end) {
        Query q = getSession().createQuery("from GrupoBean where estado = 'A' ");
        q.setMaxResults(end-start);
        q.setFirstResult(start);
        return (List<GrupoBean>)q.list();
    }

    public int countTotal() {
        Query query = getSession().createQuery("SELECT COUNT(u) FROM GrupoBean u");
        Number result = (Number)query.uniqueResult();
        return result.intValue();
    }
}
